package org.lanqiao.tjut.Controller;

import java.io.Console;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.impl.Log4JLogger;
import org.lanqiao.tjut.Bean.CourseBean;
import org.lanqiao.tjut.Bean.ScoreBean;
import org.lanqiao.tjut.Bean.TeacherBean;
import org.lanqiao.tjut.MyUtils.MyUtils;
import org.lanqiao.tjut.Service.ServiceFactory;

public class StuCourseManagerServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 学生信息管理
		String strOpt = request.getParameter("opt");
		if (strOpt != null && strOpt.trim().equals("0")) {
			// 学生成绩录入页面的跳转数据准备
			// 当前老师所教授的课程列表
			//从老师登录后获得老师id
			TeacherBean teaB = (TeacherBean) request.getSession().getAttribute("loginedTeaB");
			int teaId = MyUtils.obj2Int(teaB.getTeaid());
			//根据教师id获取课程信息
			List<CourseBean> lstCourse = ServiceFactory.getStuInfoManagerServiceInstance().getCourseInfoByTeaId(teaId);
			// 发送前台进行显示
			request.getSession().setAttribute("teaB", teaB);

			request.getSession().setAttribute("lstCourse", lstCourse);

			request.getRequestDispatcher("logined/gradeAndCourseManager/StuScoreInput.jsp").forward(request, response);
		} else if (strOpt != null && strOpt.trim().equals("1")) {
			// 查询当前课程的学生信息
			int teaId = MyUtils.obj2Int(request.getParameter("txtTeacher"));
			int courseId = MyUtils.obj2Int(request.getParameter("txtCourse"));
			List<ScoreBean> lstSco = ServiceFactory.getStuInfoManagerServiceInstance()
					.getStuInfoBy4Grade(teaId, courseId);
			request.getSession().setAttribute("lstSco", lstSco);

			request.getRequestDispatcher("logined/gradeAndCourseManager/StuScoreInput.jsp").forward(request, response);
		} else if (strOpt != null && strOpt.trim().equals("2")) {
			// 获取新增数据串
			/*String strParasScores = request.getParameter("txtscores");
			MyUtils.logger_console.debug("strParasScores---" + strParasScores);
			int i = ServiceFactory.getStuInfoManagerServiceInstance().updateStuScore(strParasScores);*/
			
			//获取新增的学生课程成绩
			String strstuid = "2";/*request.getParameter("stuscoreid");*/
			//获取新增成绩
			String strScore = "88";/*request.getParameter("txtscores");*/
			int i = ServiceFactory.getStuInfoManagerServiceInstance().updateScore(strScore,strstuid);
			if(i>0){
				//新增成绩成功
				MyUtils.logger_console.debug("已经新增学生成绩成功--------");	
				//request.getRequestDispatcher("logined/gradeAndCourseManager/StuScoreInput.jsp").forward(request, response);
			}
		}

	}
}
